package com.example.neusoft.yuejian_12.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.neusoft.yuejian_12.JavaBean.Activity;
import com.example.neusoft.yuejian_12.Listener.ActivityDetailListener;
import com.example.neusoft.yuejian_12.Model.ActivityModel;
import com.example.neusoft.yuejian_12.R;
import com.squareup.picasso.Picasso;

/**
 * Created by admin on 2017/9/26.
 */

public class ActivityDetailActivity extends AppCompatActivity {
    private LinearLayout mClub;
    private LinearLayout mClass;
    private LinearLayout mVideo;
    private Fragment mTab6;
    private Fragment mTab7;
    private Fragment mTab8;
    private Button sign;
    private ImageButton back;
    private String id;
    private Activity info;
    private String coresult;
    private String activity_name, city_name, start_date, introduction, contact_tel,
            activity_price, thumb, activity_price_stu, end_date;
    private TextView name, tel, intro, time1, price, address, price_stu, time2;
    private ImageView pic, col;

    ActivityDetailListener activityDetailListener = new ActivityDetailListener() {
        @Override
        public void onResponse(Activity listBean) {
            info = listBean;
            initData();

        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activitydetail);
        LinearLayoutManager LL = new LinearLayoutManager(this);
        final Bundle bundle = getIntent().getExtras();
        id = bundle.getString("id");
        ActivityModel model = new ActivityModel();
        model.getdetail(id, activityDetailListener);
        initViews();
        initEvents();

    }

    public void initViews() {

        sign = (Button) findViewById(R.id.btn_sign);
        back = (ImageButton) findViewById(R.id.back);
        name = (TextView) findViewById(R.id.activityname);
        pic = (ImageView) findViewById(R.id.activitypic);
        tel = (TextView) findViewById(R.id.tel);
        price = (TextView) findViewById(R.id.price);
        address = (TextView) findViewById(R.id.address);
        time1 = (TextView) findViewById(R.id.time1);
        time2 = (TextView) findViewById(R.id.time2);
        intro = (TextView) findViewById(R.id.intro);
        price_stu = (TextView) findViewById(R.id.price_stu);


    }

    public void initEvents() {


        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        sign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(ActivityDetailActivity.this,ActivitySignActivity.class);
                intent.putExtra("act_id",info.getId());
                intent.putExtra("activity_name",activity_name);
                intent.putExtra("adu_price",activity_price);
                intent.putExtra("stu_price",activity_price_stu);
                startActivity(intent);



            }
        });
    }

    public void initData() {

        activity_name = info.getActivity_name();
        city_name = info.getProvince_name() + info.getCity_name() + info.getDistrict_name() + info.getPlace();
        thumb = info.getThumb();
        start_date = info.getStart_date();
        end_date = info.getEnd_date();
        contact_tel = info.getContact_tel();
        introduction = info.getIntroduction().replaceAll("</p>","").replaceAll("<p>","");
        activity_price = info.getActivity_price();
        activity_price_stu = info.getActivity_price_stu();


        name.setText(activity_name);
        address.setText(city_name);
        tel.setText(contact_tel);
        intro.setText(introduction);
        price.setText(activity_price);
        time1.setText(start_date);
        time2.setText(end_date);
        price_stu.setText(activity_price_stu);

        if (thumb != "") {
            Picasso.with(ActivityDetailActivity.this)
                    .load("http://172.24.10.175/workout/Uploads/" + thumb)
                    .into(pic);
            pic.setScaleType(ImageView.ScaleType.FIT_XY);
        } else {
            pic.setImageResource(R.drawable.qya);
        }



    }


}








